package cn.com.cym.gamezao.web.recruit;

import cn.com.cym.gamezao.annotation.AuthToken;
import cn.com.cym.gamezao.entity.xmu.recruit.LearnExperience;
import cn.com.cym.gamezao.service.recruit.LearnExperienceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.*;


@Api(tags = "r-岗位相关")
@RestController
@RequestMapping(value = "learn")
@AuthToken(rule = "recruit.learn")
public class LearnExperienceController {

    final LearnExperienceService learnExperienceService;

    LearnExperienceController(LearnExperienceService learnExperienceService){
        this.learnExperienceService = learnExperienceService;
    }

    @ApiOperation(value = "查看学习经历！")
    @ApiOperationSupport(order = 1, author = "mr.chen")
    @GetMapping("/list")
    @AuthToken(rule = "list",require = false)
    public ResponseEntity<?> list() {
        return ResponseEntity.ok(learnExperienceService.searchByCurrentUser());
    }


    @ApiOperation(value = "新增学习经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PostMapping("/add")
    @AuthToken(rule = "add",require = false)
    public ResponseEntity<?> add(@RequestBody LearnExperience learnExperience){
        return ResponseEntity.ok(this.learnExperienceService.save(learnExperience));
    }

    @ApiOperation(value = "修改学习经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @PutMapping("/{id}")
    @AuthToken(rule = "modify",require = false)
    public ResponseEntity<?> modify(@RequestBody LearnExperience learnExperience,@NonNull @PathVariable Long id){
        return ResponseEntity.ok(this.learnExperienceService.update(learnExperience,id));
    }

    @ApiOperation(value = "删除学习经历！")
    @ApiOperationSupport(order = 2, author = "mr.chen")
    @DeleteMapping("/{id}")
    @AuthToken(rule = "delete",require = false)
    public ResponseEntity<?> deleteById(@PathVariable Long id){
        this.learnExperienceService.deleteById(id);
        return ResponseEntity.ok().build();
    }
}
